//#include "drv_common.h"
#include "dap_main.h"

#define UART_DEVICE_NAME    "uart2"
#define RINGBUFFER_SIZE     1024


static rt_device_t uart_dev;


static rt_err_t uart_recv_isr(rt_device_t dev, rt_size_t size)
{
    char c;
    rt_device_read(uart_dev, 0, &c, 1);
    chry_ringbuffer_write(&g_uartrx, &c, 1);
    
    return RT_EOK;
}

void uartx_preinit(void)
{

    uart_dev = rt_device_find(UART_DEVICE_NAME);
    rt_device_open(uart_dev, RT_DEVICE_FLAG_INT_RX);
    
    /* Set UART RX callback */
    rt_device_set_rx_indicate(uart_dev, uart_recv_isr);
}

void chry_dap_usb2uart_uart_config_callback(struct cdc_line_coding *line_coding)
{

}

void chry_dap_usb2uart_uart_send_bydma(uint8_t *data, uint16_t len)
{

    rt_device_write(uart_dev, 0, data, len);
    chry_dap_usb2uart_uart_send_complete(len); /*必须要调用这个*/
}
